package com.example.demo.dao;

import com.example.demo.bean.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface Dao {
    /*查询*/
    @Select("select * from preson")
    List<Order> find();

    //新增数据
    @Insert("insert into preson (PatName)values(#{PatName})")
    void addOrder(String PatName);


    //删除数据
    @Delete("delete from preson where PatName=#{PatName}")
    void deleteOrder(String PatName);

    //修改数据
    @Update("update preson set PatName=#{PatName}")
    void updateOrder(Order order);

    /*联表查询*/
    @Select("select p.PresonID,m.medicalID from preson p inner join medical m on m.medicalID=p.PresonID")
    List<Order> dou();

    /*联表查询*/
    @Select("SELECT p.PresonID,r.numberID FROM preson p INNER JOIN reason r ON r.numberID=p.PresonID")
    List<Order> dou1();

    /*多对多*/
    @Select("select t.PresonID,tm.medicalID from preson t join pm tm on t.PresonID = tm.medicalID")
    List<Order> dou2();

    /*多对多*/
    @Select("SELECT tt.*,\n" +
            "tm.type,\n" +
            "r.type1 \n" +
            "FROM\n" +
            "preson tt\n" +
            "INNER JOIN medical tm ON tm.medicalID = tt.medicalID\n" +
            "INNER JOIN reason r ON r.numberID= tt.numberID\n" +
            "WHERE \n" +
            "Hospital = #{Hospital}")
    List<Order> dou3(String Hospital);

    @Select("SELECT pm.medicalID,type,PatName,PatID FROM pm INNER JOIN medical ON pm.medicalID=medical.medicalID \n" +
            "INNER JOIN preson ON Hospital=#{Hospital} WHERE pm.PresonID=\n" +
            "(SELECT PresonID FROM preson WHERE Hospital=#{Hospital})\n")
    List<Order> dou4(String Hospital);

    @Select("SELECT\n" +
            "\ttype\n" +
            "FROM\n" +
            "\tpreson t\n" +
            "JOIN pm ts ON t.PresonID = ts.PresonID\n" +
            "JOIN medical s ON s.medicalID = ts.medicalID\n" +
            "WHERE\n" +
            "\tt.Hospital = #{Hospital}")
    List<Order> dou5(String Hospital);


}
